Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use int/double auto-parsing and allowed values #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seaneagan
Copy link

Note: I didn't test this, and didn't update README, but here's some other stuff unscripted provides that you can take advantage of:

Type annotating parameters with types that have a static parse method will automatically use that to validate and parse the argument, and display an error and help text if an invalid value was passed. So in this case int.parse and double.parse will be used.

allowed specifies the allowed values of an option, which will also display an error on an invalid value, and will show up in the help. Can pass a List or a Map from values to help text for each value.

Either type annotating an option as a List, or specifying allowMultiple will mean you can specify option multiple times on the command line, and they will be passed to the function as a List. I filed a bug for unscripted to support comma separated values:

seaneagan/unscripted#49

You probably won't want to actually merge this, as I didn't test it, and didn't update README, but here's some other stuff unscripted provides that you can take advantage of:

Type annotating parameters with types that have a static `parse` method will automatically use that to validate and parse the argument, and display an error and help text if an invalid value was passed.  So in this case `int.parse` and `double.parse` will be used.

`allowed` specifies the allowed values of an option, which will also display an error on an invalid value, and will show up in the help.  Can pass a List or a Map from values to help text for each value.

Either type annotating an option as a List, or specifying `allowMultiple` will mean you can specify option multiple times on the command line, and they will be passed to the function as a List.  I filed a bug for unscripted to support comma separated values:

seaneagan/unscripted#49
@alexgann
Copy link
Member

@seaneagan - thanks so much! I had originally tried with int/double but get the following error whenever I try:

Unhandled exception:
Class '_LocalClassMirror' has no instance method '[]'.

NoSuchMethodError: method not found: '[]'
Receiver: Instance of '_LocalClassMirror'
Arguments: [Instance of 'Symbol']
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:45)
#1      getParserFromType (package:unscripted/src/util.dart:172:29)
#2      getUsageFromFunction.<anonymous closure> (package:unscripted/src/util.dart:131:33)
#3      IterableBase.forEach (dart:collection/iterable.dart:222)
#4      getUsageFromFunction (package:unscripted/src/util.dart:111:61)
#5      DeclarationScript.usage (package:unscripted/src/script_impl.dart:69:42)
#6      ScriptImpl.execute (package:unscripted/src/script_impl.dart:27:55)
#7      main (file:///C:/Users/agann/GitHub/SoundDart/bin/sounddart.dart:12:56)
#8      _startIsolate.isolateStartHandler (dart:isolate-patch/isolate_patch.dart:216)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:116)

@seaneagan
Copy link
Author

Ah, they removed a feature from dart:mirrors that I was using. Fixed in unscripted 0.3.2:

http://pub.dartlang.org/packages/unscripted

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants